<template>
	<view class="detail" v-show="dataForm.name ? true : false" :style="{ '--price': vuex_config.price }">
		<view class="banner">
			<image class="b-img" :src="dataForm.logo || img" mode="aspectFill"></image>
		</view>
		<view class="box">
			<view class="title">{{ dataForm.name }}</view>
			<view class="address_box" v-if="dataForm.address ? true : false">
				<view class="sign iconfont iconfont-e657"></view>
				<view class="address_detail u-line-2">{{ dataForm.address }}</view>
				<view @click="goLocation" class="address_btn iconfont iconfont-e620"
					v-if="dataForm.coordinate ? true : false">导航</view>
			</view>
			<view v-if="dataForm.introduce" class="ftitle">{{ dataForm.introduce }}</view>
		</view>
		<view class="product-title">
			<text>全部商品</text>
			<text class="text">在售商品{{ dataForm.pro_count }}件</text>
		</view>
		<view class="list">
			<view class="item" v-for="(item, index) in dataList" :key="index" @click="open(item)">
				<image class="item-img" :src="item.logo" mode="aspectFill"></image>
				<view class="item-box">
					<view class="box-title u-line-1">{{ item.name }}</view>
					<view class="box-price">￥{{ item.price }}</view>
				</view>
			</view>
		</view>
		<sww-load-more :params="dataListParams"></sww-load-more>
	</view>
</template>

<script>
	import {
		pagingMixin
	} from '@/mixins/pagingMixin';
	import {
		pageShare
	} from '@/mixins/pageShare';
	export default {
		mixins: [pageShare, pagingMixin],
		data() {
			return {
				dataForm: {},
				supplierId: null,
				img: require('@/static/icon/shop_img.png')
			};
		},
		onLoad(options) {
			if (options && options.id) {
				this.supplierId = Number(options.id);
				this.initPage(options.id);
				this.getDataList();
			}
		},
		onReachBottom() {
			this._load_data();
		},
		onShareAppMessage: function() {
			return this.getShareAppMessage();
		},
		onShareTimeline: function() {
			let obj = this.getShareTimeline();
			return obj;
		},
		methods: {
			initPage(id) {
				this.$loading();
				this.$resPost('GetProductSupplierInfo', {
					pk_id: id
				}).then(res => {
					this.dataForm = res.data;
					this.customShareParams();
					this.$hide();
				});
			},
			open(item) {
				this.$toProd({
					...item,
					prodType: 1
				});
			},
			// 设置当前产品页的分享参数
			customShareParams() {
				if (!this.shareParams.title) {
					let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
					let curRoute = routes[routes.length - 1].route; //获取当前页面路由
					let curParam = routes[routes.length - 1].options; //获取路由参数
					this.shareParams = {
						title: this.dataForm.name,
						path: curRoute,
						query: curParam,
						imgUrl: this.dataForm.logo || ''
					};
					this.onShareByH5();
				}
			},
			getDataList() {
				this._init_data('GetProductList', {
					supplier_id: this.supplierId
				});
			},
			goLocation() {
				let arr = this.dataForm.coordinate.split(',');
				let adressArr = this.dataForm.address.split(',')
				let obj = {
					name: adressArr[0] || '',
					address: adressArr[1] || ''
				};
				uni.openLocation({
					latitude: Number(arr[0] || 0),
					longitude: Number(arr[1] || 0),
					...obj,
				});
			}
		}
	};
</script>
<style>
	page {
		background-color: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.detail {
		.banner {
			width: 100%;
			height: 400rpx;

			.b-img {
				width: 100%;
				height: 100%;
			}
		}

		.text {
			font-size: 24rpx;
			color: #999;
			font-weight: 500;
		}

		.box {
			padding: 20rpx 26rpx;
			background-color: #fff;
			display: flex;
			flex-direction: column;
			width: 100%;

			.title {
				font-size: 32rpx;
				color: #333;
				font-weight: bold;
			}

			.address_box {
				margin-top: 6rpx;
				display: flex;
				align-items: center;

				.sign {
					font-size: 46rpx;
				}

				.address_detail {
					flex: 1;
					overflow: hidden;
					padding: 0 16rpx;
				}

				.address_btn {
					background-color: #8740b3;
					color: #fff;
					border-radius: 10rpx;
					line-height: 54rpx;
					padding: 0 16rpx 0 12rpx;
					font-size: 26rpx;
				}
			}

			.ftitle {
				font-size: 26rpx;
				color: #999;
				margin-top: 16rpx;
				text-indent: 2em;
			}
		}

		.product-title {
			width: 100%;
			padding: 30rpx 26rpx;
			font-size: 32rpx;
			color: #333;
			font-weight: bold;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.list {
			padding: 0 26rpx;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
			width: 100%;

			.item {
				width: 49%;
				border-radius: 10rpx;
				background-color: #fff;
				margin-bottom: 20rpx;
				overflow: hidden;

				.item-img {
					width: 100%;
					height: 320rpx;
				}

				.item-box {
					padding: 20rpx;
					display: flex;
					flex-direction: column;

					.box-title {
						font-size: 24rpx;
						color: #333;
						margin-bottom: 20rpx;
					}

					.box-price {
						color: var(--price);
						font-size: 28rpx;
					}
				}
			}
		}
	}
</style>
